package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.User;
import com.tanhua.dubbo.api.db.UserApi;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service //这里是dubbo的注解
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String mobile) {
//        select * from biaoming where mobile=?

        QueryWrapper<User> queryWrapper = new QueryWrapper();
//        queryWrapper.eq("mobile",mobile);
        queryWrapper.lambda().eq(User::getMobile,mobile); //可以不用再看表中的列名

        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public Long save(User user) {
        int i = userMapper.insert(user); //返回的数据是1 或者 0 1：成功  0：失败
//        对象插入后 对象中的ID就自动有值了
        return user.getId();
    }

    //更新用户
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }


}
